/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.util;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;

/**
 *
 * @author Meanz
 */
public class Screen {

    public static ByteBuffer get2dPixel(float x, float y) {
        IntBuffer viewport = BufferUtils.createIntBuffer(16);
        FloatBuffer modelview = BufferUtils.createFloatBuffer(16);
        FloatBuffer projection = BufferUtils.createFloatBuffer(16);
        float winX, winY, winZ;
        FloatBuffer position = BufferUtils.createFloatBuffer(3);
        GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
        GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
        GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
        winX = (float) x;
        winY = (float) viewport.get(3) - (float) y;
        winZ = 1f;
        ByteBuffer pixels = ByteBuffer.allocateDirect(3);
        GL11.glReadPixels((int) winX, (int) (viewport.get(3) - winY), 1, 1, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, pixels);
        return pixels;
    }
}
